package com.yxjx.duoxue.versionupdate;

import org.json.JSONException;
import org.json.JSONObject;

import com.yxjx.duoxue.datamodel.DMObject;
import com.yxjx.duoxue.utils.UIHelper;

/**
 * 升级描述文件
 *
 * @author zhangxs
 * @date 2015年3月24日
 *
 */
public class ConfigUpdateVersionDTS extends DMObject implements java.io.Serializable {

    private static final long serialVersionUID = 3610954839260303693L;

    // 当前版本号
    private Integer version = 0;
    // 当前版本号
    private String versionStr = "";
    // 系统类型,1iOS,2android
    private Integer type = 0;
    // 标题
    private String title = "";
    // 描述
    private String des = "";
    // 0不需要升级，1需要升级
    private Integer needUpdate = 0;
    // 需要升级的最低版本号
    private Integer updateVersion = 0;
    // 需要升级的最低版本号
    private String updateVersionStr = "";
    // 升级地址（预留）
    private String updateUrl = "";

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public String getVersionStr() {
        return versionStr;
    }

    public void setVersionStr(String versionStr) {
        this.versionStr = versionStr;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des;
    }

    public Integer getNeedUpdate() {
        return needUpdate;
    }

    public void setNeedUpdate(Integer needUpdate) {
        this.needUpdate = needUpdate;
    }

    public Integer getUpdateVersion() {
        return updateVersion;
    }

    public void setUpdateVersion(Integer updateVersion) {
        this.updateVersion = updateVersion;
    }

    public String getUpdateVersionStr() {
        return updateVersionStr;
    }

    public void setUpdateVersionStr(String updateVersionStr) {
        this.updateVersionStr = updateVersionStr;
    }

    public String getUpdateUrl() {
        return updateUrl;
    }

    public void setUpdateUrl(String updateUrl) {
        this.updateUrl = updateUrl;
    }

    @Override
    public String toString() {
        return "{\"version\":\"" + version + "\", \"versionStr\":\"" + versionStr + "\", \"type\":\"" + type + "\", \"title\":\"" + title + "\", \"des\":\"" + des
                + "\", \"needUpdate\":\"" + needUpdate + "\", \"updateVersion\":\"" + updateVersion + "\", \"updateVersionStr\":\"" + updateVersionStr
                + "\", \"updateUrl\":\"" + updateUrl + "\"}";
    }
    
    /**
     * cast str to ConfigUpdateVersionDTS object
     * @param str
     * @return
     */
    public static ConfigUpdateVersionDTS from(String str) {
    	if (UIHelper.isEmpty(str)) {
    		return null;
    	}
		try {
			JSONObject jo = new JSONObject(str);
			ConfigUpdateVersionDTS item = new ConfigUpdateVersionDTS();
			item.setDes(castString(jo,"des"));
			item.setNeedUpdate(castInteger(jo,"needUpdate"));
			item.setUpdateUrl(castString(jo,"updateUrl"));
			return item;
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
    }

}